package com.z.ssmdemo.filter;

import com.z.ssmdemo.constant.KeyContant;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 21051
 */
public class LoginValidateFilter implements Filter {

    private static String loginUrl = "/DispatchServlet/login";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //filterConfig.
        //todo 初始化
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //HttpServletRequest request = (HttpServletRequest) servletRequest;
        //HttpSession httpSession = request.getSession();
        //String username = (String)httpSession.getAttribute(KeyContant.USER_NAME_IN_SESSION);
        //if (username == null) {
        //    HttpServletResponse response = (HttpServletResponse)servletResponse;
        //    response.sendRedirect(loginUrl);
        //}
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
